﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DemoQLKhoSX.BusinessLogicLayer;
using DemoQLKhoSX.EntityClasses;
using DemoQLKhoSX.Library;

namespace DemoQLKhoSX.PresentationLayer
{
    public partial class FrmLogin : Form
    {
        private UserBLO _userLoginB = new UserBLO();

        public FrmLogin()
        {
            InitializeComponent();
        }

        private void btnHuy_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void btnDangNhap_Click(object sender, EventArgs e)
        {
            if (txtTenDangNhap.Text.Trim() == "")
            {
                MessageBox.Show("Hãy nhập tên đăng nhập");
                txtTenDangNhap.Focus();
                return;
            }
            if (txtMatKhau.Text.Trim() == "")
            {
                MessageBox.Show("Hãy nhập mật khẩu");
                txtMatKhau.Focus();
                return;
            }
            //Check with data entity
            UserEntity _userloginE = new UserEntity();
            _userloginE = _userLoginB.getUserByUNPA(txtTenDangNhap.Text,txtMatKhau.Text);
            if (_userloginE.idUser.ToString() != "")
            {
                CurrentInformation.CurrentUser = _userloginE;
                CurrentInformation.UserLogon = true;
                this.Close();
            }
            else
            {
                CurrentInformation.UserLogon = false;
                MessageBox.Show("Đăng nhập thất bại");
            }
        }
    }
}
